import {listModule, listType, addTask} from '_api/statistic/task'
import {_Promise} from "_libs/util";

export default {
  namespaced: true,
  state: {
    typeList: [],
    moduleList: []
  },
  mutations: {
    setTypeList(state, typeList) {
      state.typeList = typeList
    },
    setModuleList(state, moduleList) {
      state.moduleList = moduleList
    }
  },
  actions: {
    // 获取所有模块
    listModule({commit}) {
      return _Promise(listModule(), res => {
        commit('setModuleList', res.data)
      })
    },

    // 获取所有类型
    listType({commit}) {
      return _Promise(listType(), res => {
        commit('setTypeList', res.data)
      })
    },

    // 创建任务
    addTask(context, task) {
      return _Promise(addTask(task))
    }
  }
}
